package application

import (
	"pdemo/bff/internal/infrastructure/clientset"
	"pdemo/service-hello/api"
)

type Example struct {
	*clientset.ClientSet
}

func (e *Example) Hello(ctx Context) (interface{}, error) {
	name := ctx.Vars().Get("name")
	resp, err := e.TemplateClient.Hello(ctx, &api.HelloRequest{Name: name})

	return resp, err
}

func (e *Example) Add(ctx Context) (interface{}, error) {
	req := struct {
		A int64 `json:"a"`
		B int64 `json:"b"`
	}{}

	if err := ctx.BindQuery(&req); err != nil {
		return nil, err
	}

	return e.TemplateClient.Add(ctx, &api.AddRequest{
		A: req.A,
		B: req.B,
	})
}
